package com.boot.mgt.service.impl

import com.boot.core.result.ResultTo
import com.boot.mgt.dao.mysql.TaHmsPushMapper
import com.boot.mgt.model.TaHmsPush
import com.boot.mgt.service.TaHmsPushService
import com.github.pagehelper.PageHelper
import com.github.pagehelper.PageInfo
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * @author kawins
 * createTime 2018-10-23 16:24
 */
@Service
@AutoJsonRpcServiceImpl
class TaHmsPushServiceImpl : TaHmsPushService {

    @Autowired
    protected lateinit var taHmsPushMapper: TaHmsPushMapper

    override fun sendSuccess(msgId: Int): Boolean {
        taHmsPushMapper.selectByPrimaryKey(msgId)?.apply {
            isSuccess = true
            taHmsPushMapper.updateByPrimaryKeySelective(this)
        }
        return false
    }

    override fun searchMqMessage(police_number: String): List<TaHmsPush>? {
        return taHmsPushMapper.searchMqMessage(police_number)
    }

    override fun msgList(page_index: Int?, page_size: Int?, hmsType: Int?, police_number: String?): ResultTo {
        PageHelper.startPage<Any>(page_index ?: 1, page_size ?: 20)
        val taHmsPush = TaHmsPush().apply {
            policeNumber = police_number
            this.hmsType = hmsType
        }
        val list = taHmsPushMapper.select(taHmsPush)
        val pageInfo = PageInfo(list)
        return ResultTo().apply {
            this["msg_list"] = list
            this["page_index"] = page_index ?: 1
            this["page_amount"] = pageInfo.pages
            this["page_total"] = pageInfo.total
        }
    }

}